Skip to content

Add checks for valid response and retries to fetch_posts() - #481

Merged
sco1 merged 6 commits into
python-discord:masterfrom
bendiller:fetch_posts_retries
Oct 3, 2019
Merged

sco1 merged 6 commits into
python-discord:masterfrom
bendiller:fetch_posts_retries

Conversation

@bendiller

@bendiller bendiller commented Oct 1, 2019 •

Copy link
Copy Markdown
Contributor

Fixes #390

Added checks for response.status and response.content_type for fetch_posts() to validate the response from self.bot.http_session.get(). Also added retries in case a bad response is received.

It's been tested to verify that the !reddit top (and similar) commands still work, and I simulated some retry behavior by specifying intentionally bad routes. Please let me know what changes you'd like to see!

MarkKoz
MarkKoz previously approved these changes Oct 2, 2019

@MarkKoz MarkKoz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could still error out on content["data"]["children"] if it gets a JSON response in a format it doesn't expect, but at that point it's likely programmer error so the error should loudly present itself I think.

@MarkKoz
MarkKoz dismissed their stale review October 2, 2019 05:05

On second thought, I think some logging would be good to have so that we aren't completely in the dark about invalid responses happening. Probably a debug log level is good enough.

Comment thread bot/cogs/reddit.py Resolved
@MarkKoz MarkKoz added area: cogs t: bug Something isn't working labels Oct 2, 2019
Comment thread bot/cogs/reddit.py Resolved
Comment thread bot/cogs/reddit.py Resolved
benj028 and others added 2 commits October 3, 2019 15:58

@MarkKoz MarkKoz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this and it works great. Thanks!

@bendiller

Copy link
Copy Markdown
Contributor Author

Thanks Mark, that's exciting! Particularly because you've personally assisted me in the Discord more than once, haha. Cheers.

@sco1
sco1 merged commit 75c22d5 into python-discord:master Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Reddit cog occassionally fails to relay new /r/python messages

5 participants